package org.example.struct.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/8/22 10:21
 * @apiNote
 */

public class Test01287FindSpecialInteger {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,2,6,6,6,6,7,10};
        int res = test(arr);
        System.out.println(res);
    }

    public static int test(int[] arr) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            map.put(arr[i],map.getOrDefault(arr[i],0)+1);
        }
        int limit = arr.length/4;
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
            if(entry.getValue() > limit){
                return entry.getKey();
            }
        }
        return -1;
    }

    public static int test1(int[] arr){
        int limit = arr.length/4;
        for(int i = 0; i<arr.length;i++){
            if(arr[i+limit] == arr[i]){
                return arr[i];
            }
        }
        return -1;
    }

}
